package cn.iocoder.yudao.module.promotion.groupon.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.promotion.groupon.pojo.dto.AppGrouponPackageFavoriteSaveDTO;
import cn.iocoder.yudao.module.promotion.groupon.pojo.vo.AppGrouponPackageFavoriteVO;
import cn.iocoder.yudao.module.promotion.groupon.service.app.AppGrouponPackageFavoriteService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;

@Tag(name = "用户 App - 团购套餐")
@RestController
@RequestMapping("/promotion/groupon-package/favorite")
public class AppGrouponPackageFavoriteController {
    @Resource
    private AppGrouponPackageFavoriteService appGrouponPackageFavoriteService;

    @PostMapping("/toggle")
    @Operation(summary = "收藏/取消收藏")
    public CommonResult<Boolean> toggle(@Valid @RequestBody AppGrouponPackageFavoriteSaveDTO reqVO) {
        return success(appGrouponPackageFavoriteService.toggle(reqVO.getPackageId(), getLoginUserId()));
    }

    @GetMapping("/page")
    @Operation(summary = "获得收藏分页")
    public CommonResult<PageResult<AppGrouponPackageFavoriteVO>> page(@Valid PageParam reqVO) {
        return success(appGrouponPackageFavoriteService.getPage(reqVO.getPageNo(), reqVO.getPageSize(), getLoginUserId()));
    }

}
